package com.utils.conmponentbase.widget;

import android.content.Context;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatImageView;

import com.zhpan.bannerview.provider.ViewStyleSetter;
import com.zhpan.bannerview.utils.BannerUtils;

/**
 * MvvmDemo com.utils.conmponentbase.widget
 * 2020-01-10 13:47
 * 圆角图片 ImageView
 */
public class RoundImageView extends AppCompatImageView {
    private int radius = BannerUtils.dp2px(6);

    public RoundImageView(Context context) {
        super(context);
        setRoundCorner();
    }

    public RoundImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setRoundCorner();
    }

    public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setRoundCorner();
    }

    private void setRoundCorner() {
        ViewStyleSetter setter = new ViewStyleSetter(this);
        setter.setRoundRect(radius);
    }

    public void setRadius(int pRadius) {
        radius = BannerUtils.dp2px(pRadius);
    }
}
